package com.woniu.userassembly.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.ly.model.model.PlatfromStatement;
import com.woniu.ly.model.model.Product;
import com.woniu.ly.model.model.User;
import com.woniu.ly.model.model.UserOrderDetail;
import com.woniu.userassembly.model.UserAccount;
import com.woniu.userassembly.model.UserOrder;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper extends BaseMapper<UserOrder> {
    @Select("select * from t_user where user_name=#{userName}")
     User login(String userName);
    @Insert("insert into t_user(user_name,user_password,user_tel) values(#{userName},#{userPassword},#{userTel}) ")
     void register(@Param("userName") String userName, @Param("userPassword")String userPassword,@Param("userTel") String userTel);
    @Select("select a3.role_name from t_user_role as a1 join t_user as a2 join t_role as a3 on a1.user_id=a2.user_id and a1.role_id=a3.role_id where a2.user_name=#{userName}")
    String quanxian(String userName);

    List<Product> selectProduct(String keyWord);
    @Select("select * from t_user_order where user_id=#{userId} order by user_order_id DESC limit #{pageIndex},#{pageNum}")
    List<UserOrder> selectOrder(@Param("pageIndex") int pageIndex, @Param("pageNum") int pageNum,@Param("userId")int userId);
@Select("select count(user_order_id) from t_user_order where user_id=#{userId}")
    int orderCount(int userId);
@Delete("delete from t_user_order where user_order_id=#{orderId}")
    void cancelOrder(int orderId);
@Insert("insert into t_user_order_detail(user_order_detail_price,user_order_id,traveler_id,user_order_detail_status) values(#{userOrderDetailPrice},#{userOrderId},#{travelerId},#{userOrderDetailStatus})")
    void makeOrderDetail(UserOrderDetail userOrderDetail);
@Delete("delete from t_user_order_detail where user_order_id=#{orderId}")
    void cancelOrderDetail(int orderId);
@Select("select user_order_price from t_user_order where user_order_id=#{orderId}")
    double selectOrderPrice(int orderId);
    @Select("select user_id from t_user_order where user_order_id=#{orderId}")
    int selectOrderUserId(int orderId);
@Update("update t_user_order set user_order_status='退款' where user_order_id=#{orderId}")
    void refundOrder(int orderId);
@Select("select user_order_id from t_user_order")
    List<Integer> selectOrderIdd();
@Update("update t_user_order set user_order_status='已付款' where user_order_id=#{orderId}")
    void pay(int orderId);
@Insert("insert into t_user_account(user_account_type,user_account_money,user_account_content,user_account_time,user_id) values(#{userAccountType},#{userAccountMoney},#{userAccountContent},#{userAccountTime},#{userId})")
    void refundOrderPrice(UserAccount updateTourId);
@Insert("insert into t_user_account(user_account_type,user_account_money,user_account_content,user_account_time,user_id) values(#{userAccountType},#{userAccountMoney},#{userAccountContent},#{userAccountTime},#{userId})")
    void userAccount(UserAccount userAccount);
@Select("select user_id from t_user ORDER BY user_id DESC LIMIT 0,1;")
    int registerId();
@Insert("insert into t_user_role(user_id,role_id) values(#{userId},1)")
    void insertUserRole(int userId);
@Select("select tour_price from t_seckill_tour where seckill_tour_id=#{seckillTourId}")
    double selectSeckillTourPrice(int seckillTourId);
    @Update("update t_user_order_detail set user_order_detail_status='退款' where traveler_id=#{traId}")
    void refundTraveler(int traId);
@Insert("insert into t_platfrom_account(platfrom_account_money,statement_id) values(#{price},#{id})")
    void platformAccount(@Param("price") double price,@Param("id") int id);
@Select("select platfrom_account_money from t_platfrom_account order by platfrom_account_id DESC limit 0,1")
    double selectLastPlatformAccount();
@Select("select tour_id from t_user_order where user_order_id=#{orderId}")
    int findTraveler(int orderId);
    @Select("select count(traveler_id) from t_user_order_detail where user_order_id=#{tourId}")
    int travelNum(int tourId);
@Select("select user_tel from t_user")
    List<String> selectTel();
@Update("update t_user set card_id=#{cardId} where user_tel=#{travelerTel}")
    void insertCardId(@Param("cardId") int cardId,@Param("travelerTel") String travelerTel);
}
